package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.domain.RefPartExcel;

import com.bjpowernode.springboot.domain.Student;
import com.bjpowernode.springboot.domain.Students;
import com.bjpowernode.springboot.service.StudentService;
import com.bjpowernode.springboot.util.ExcelUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright (C), 2021-2021, 颜子初
 * Author: yan
 * Date: 2021/11/12 14:41
 * FileName: ExcelController
 * Description: excel
 */
@RestController
@RequestMapping("/excel")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("fileUpload")
    public List<Student> up(MultipartFile file) throws Exception {
        if (file.isEmpty()) {
            //return "文件不能为空";
            return null;
        }
        //判断是否是excel文件
        List<Student> studentList = ExcelUtil.readExcel(file,Student.class);

        Students students = new Students(studentList);

        studentService.saveMulti(students);

        return studentList;
    }
}
